﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;

namespace FRM_Main
{
    public partial class FRM_ThemNguoiDung : DevExpress.XtraEditors.XtraForm
    {
        Quan_Tri_He_ThongEntities5 context = new Quan_Tri_He_ThongEntities5();
        public FRM_ThemNguoiDung()
        {
            InitializeComponent();
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            //NguoiDung ND = new NguoiDung();
            //ND.HoVaTenLot = txtHoTenLot.Text;
            //ND.Ten = txtTen.Text;
            //ND.TenVietTat = txtTenVietTat.Text;
            //ND.GioiTinh = "";

            //ND.NgaySinh = dtNgaySinh.Value;
            //ND.MaPhongBan = Int32.Parse(cmbPhongBan.SelectedValue.ToString());
            //ND.DienThoaiDiDong = txtDTDD.Text;
            //ND.Email = txtEmail.Text;
            //ND.TenDangNhap = txtTenDangNhap.Text;
            //ND.MatKhau = txtMatKhau.Text;
            //context.AddToNguoiDungs(ND);
            //int count = context.SaveChanges();


            // MessageBox.Show(Convert.ToString(dtNgaySinh.Value));
            int[] a = new int[3];
            if (chk.GetItemChecked(0))
                a[0] = 1;
            if (chk.GetItemChecked(1))
                a[1] = 2;
            if (chk.GetItemChecked(2))
                a[2] = 3;
           MessageBox.Show(""+ a[0]+ a[1] + a[2]);
            int? returnvalue = context.SP_NGUOIDUNG_INSERT(txtHoTenLot.Text,
                                                     txtTen.Text,
                                                     txtTenVietTat.Text,
                                                     cmbGioiTinh.Text,
                                                     dtNgaySinh.Value,
                                                     Int32.Parse(cmbPhongBan.SelectedValue.ToString()),
                                                     txtDTDD.Text,
                                                     txtEmail.Text,
                                                     txtTenDangNhap.Text,
                                                     txtMatKhau.Text, a[0], a[1], a[2]).SingleOrDefault();
            if (returnvalue == 1)
            {
                MessageBox.Show("Thêm người dùng thành công!");
                this.Close();
            }
            else
            {
                MessageBox.Show("Thêm người dùng không thành công");
            }

        }

        private void FRM_ThemNguoiDung_Load(object sender, EventArgs e)
        {
            cmbPhongBan.DataSource = context.SP_PHONGBAN_SELECT().ToList<PhongBan>();
            cmbPhongBan.DisplayMember = "TenPhongBan";
            cmbPhongBan.ValueMember = "MaPhongBan";

        }
    }
}